package com.cloudkinto.appletController.statistics;

import com.cloudkinto.appletservice.covershows.AppletNewsInformationService;
import com.cloudkinto.appletservice.covershows.AppletNotificationService;
import com.cloudkinto.appletservice.covershows.AppletVideoInformationService;
import com.cloudkinto.appletservice.statistics.AppletStatisticsService;
import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangyy
 * @date 2020/6/19 9:24
 * @description:
 */
@RestController
@Api(tags = "小程序首页模块")
@RequestMapping("/api/applet/census")
public class AppletStatisticsController extends BaseController {

    @Autowired
    private AppletNotificationService notificationService;
    @Autowired
    private AppletStatisticsService service;
    @Autowired
    private AppletNewsInformationService newsInformationService;
    @Autowired
    private AppletVideoInformationService videoInformationService;


    @UserSessionRequired
    @GetMapping("/notificationList")
    @ApiOperation(value = "消息通知", notes = "统计")
    public SingleResult notification(HttpServletRequest request) {
        Map<String, String> map = new HashMap<>();
        String current = request.getParameter("current");
        String pageSize = request.getParameter("pageSize");
        map.put("current", current);
        map.put("pageSize", pageSize);
        return SingleResult.success(notificationService.getListPage(map));
    }

    @UserSessionRequired
    @GetMapping("/getCompanyAccount")
    @ApiOperation(value = "获取公司标识和余额", notes = "统计")
    public SingleResult getCompanyAccount() {
        Long companyId = getCompanyId();
        Long userId = getCurrentUserId();
        return service.getCompanyAccount(userId, companyId);
    }

    @UserSessionRequired
    @GetMapping("/statistics")
    @ApiOperation(value = "数量统计", notes = "统计")
    public SingleResult statistics() {
        Long companyId = getCompanyId();
        Long userId = getCurrentUserId();
        return service.appletStatistics(userId, companyId);
    }

    @UserSessionRequired
    @GetMapping("/newsInformationList")
    @ApiOperation(value = "新闻资讯列表", notes = "查询（分页）")
    public PageResult listPage(HttpServletRequest request) {

        Map<String, String> map = new HashMap<>();
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("current", current);
        map.put("pageSize", size);
        return newsInformationService.getListPage(map);
    }

    @UserSessionRequired
    @GetMapping("/videoInformationList")
    @ApiOperation(value = "视频资源列表", notes = "查询（分页）")
    public PageResult videoInformationList(HttpServletRequest request) {
        Map<String, String> map = new HashMap<>();
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("current", current);
        map.put("pageSize", size);
        return videoInformationService.getListPage(map);
    }

    @UserSessionRequired
    @GetMapping("/newsInformation/{id}")
    @ApiOperation(value = "新闻资讯详情", notes = "查询")
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success(newsInformationService.detail(id));
    }


}
